package app.sub;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserDao userDao;

    @Cacheable(value = "user_info", keyGenerator = "demoKeyGenerator")
    public User getById(Integer id) {
        System.out.println("从数据库中查询的");
        User user = userDao.findOne(id);
        return userDao.findOne(id);
    }

    @CacheEvict(value = "user_info", allEntries = true)
    public void update() {
        System.out.println("清除缓存");
    }
}